package main

import (
	"flag"
	"log"
	"net/http"
	"webSocket/lib"
)

var addr = flag.String("addr", "0.0.0.0:8777", "请输入server地址")

func init() {
	log.SetFlags(log.Lmicroseconds | log.Llongfile | log.Ldate)
}

func main() {
	flag.Parse()

	http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
		lib.ServerWs(w, r)
		log.Println(lib.ConnMap)
	})
	log.Println("http.ListenAndServe on ", *addr)
	err := http.ListenAndServe(*addr, nil) //阻塞listen

	if err != nil {
		log.Panicln("http.ListenAndServe", err)
	}
}
